package com.hkpickup.demo;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReadPropertyServlet extends HttpServlet {
	static public Properties properties;
	
	public ReadPropertyServlet() throws IOException{
		
//		ServletContext context = getServletContext();
//		InputStream is = context.getResourceAsStream("/WEB-INF/My.properties");
//		
//		properties = new Properties(); 
//		properties.load(is);
		properties = new Properties(); 
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("My.properties");
		properties.load(is);
		is.close();
		
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		//super.doGet(req, resp);
		String x = properties.getProperty("user", "none");
		resp.getWriter().println("user "+ x) ;
	}


	
	

	
	
	
}
